/*
 * ! Ext JS Library 4.0 Copyright(c) 2006-2011 Sencha Inc. licensing@sencha.com
 * http://www.sencha.com/license
 */
Ext.define('MyDesktop.App', {
	extend : 'Ext.ux.desktop.App',
	init : function() {
		// custom logic before getXYZ methods get called...
		this.callParent();
		// now ready...
	},

	getModules : function() {
		return [
		// new MyDesktop.VideoWindow(),
		// new MyDesktop.Blockalanche(),
		// new MyDesktop.SystemStatus(),
		// new MyDesktop.GridWindow(),
		// new MyDesktop.TabWindow(),
		// new MyDesktop.AccordionWindow(),
		// new MyDesktop.Notepad(),
		// new MyDesktop.BogusMenuModule(),
		// /new MyDesktop.BogusModule()
		];
	},

	getDesktopConfig : function() {
		var me = this, ret = me.callParent();
		return Ext.apply(ret, {
					// cls: 'ux-desktop-black',

					contextMenuItems : [{
								text : '桌面背景',
								iconCls : 'hh_zmbj',
								handler : me.onSettings,
								scope : me
							}, {
								text : '修改主题',
								iconCls : 'hh_zt',
								handler : Desktop.onTheme,
								scope : me
							}],

					shortcuts : Ext.create('Ext.data.Store', {
						model : 'Ext.ux.desktop.ShortcutModel',
						data : static_var.loginuser.hhXtYhCdZmtbList
							/*
							 * [ { name: 'Grid Window', iconCls:
							 * 'grid-shortcut', module: 'grid-win' }, { name:
							 * '通讯工具', iconCls: 'accordion-shortcut', module:
							 * 'acc-win' }, { name: '记事本', iconCls:
							 * 'notepad-shortcut', module: 'notepad' }, { name:
							 * '系统状态', iconCls: 'cpu-shortcut', handler:
							 * function(){Ext.Msg.alert("","");}} ]
							 */
						}),

					wallpaper : static_var.loginuser.hhXtZmsx.vzmbj,
					wallpaperStretch : false
				});
	},
	addActionFormItems : function(parent, childrenList) {
		parent.menu = {};
		parent.menu.items = [];
		for (var i = 0; i < childrenList.length; i++) {
			childrenList[i].icon = '/hhcommon/images/extjsico/smhhsshe.jpg';
			childrenList[i].vsj = 'com.hh.form.actionform.PageList';
			childrenList[i].action = 'com.hh.form.actionform.PageList';
			childrenList[i].handler = Menu.newWindow;
			var children = childrenList[i];
			parent.menu.items.push(children);
			if (children.children != null) {
				this.addActionFormItems(children, children.children);
			}
		}
		if (parent.menu.items.length == 0) {
			parent.menu = null;
		}
	},
	// 配置为开始菜单
	getStartConfig : function() {
		var me = this;
		var cfg = {
			app : me,
			menu : []
		};

		Ext.apply(cfg, me.startConfig);

		var menu = [];

		var hhXtCdList = static_var.loginuser.hhXtCdList;
		for (var i = 0; i < hhXtCdList.length; i++) {
			var hhXtCd = hhXtCdList[i];
			if (hhXtCd.node == 'root') {
				var startMenu = {
					text : hhXtCd.text,
					icon : hhXtCd.icon,
					id : hhXtCd.id,
					handler : Menu.newWindow,
					vsj : hhXtCd.vsj
				};
				Ext.apply(startMenu, hhXtCd);
				Menu.addMenuChildren(hhXtCdList, startMenu);
				menu.push(startMenu);
			}

		}
//动态表单
//		var actionformitems = Request.synRequestObject(
//				'system-Data-queryAllDataTreeByTypeAndPid', {
//					type : 'form_tree'
//				});
//
//		Menu.actionFormId = UUID.getUUID();
//
//		var actionform = {
//			text : '动态表单',
//			icon : '/hhcommon/images/extjsico/smhhsshe.jpg',
//			id : Menu.actionFormId,
//			handler : Menu.newWindow,
//			vsj : 'com.hh.global.NavigAtionWindow'
//		};
//		me.addActionFormItems(actionform, actionformitems);
//		menu.push(actionform);
//
//		Menu.childrenList = actionformitems;
		//动态表单
		
		
		// var menu =eval("(" +"[{text: 'More items', iconCls: 'bogus', handler:
		// function() { var dlg = new com.hh.system.desktop.Settings().show() }
		// }]"+")");
		cfg.menu = menu;
		cfg.app = me.callParent().app;
		Ext.apply(cfg, {
			title : static_var.loginuser.text
					+ " ( "
					+ static_var.loginuser.vdlzh
					+ " )&nbsp;&nbsp;&nbsp; "
					+ (static_var.currOrg.text == null
							? ""
							: static_var.currOrg.text),
			iconCls : static_var.loginuser.nxb == 1 ? 'user' : 'user-girl',
			height : 300,
			toolConfig : {
				width : 100,
				enableOverflow : true,
				items : [{
							text : '桌面背景',
							iconCls : 'hh_zmbj',
							handler : me.onSettings,
							scope : me
						}, {
							text : '修改主题',
							iconCls : 'hh_zt',
							handler : Desktop.onTheme,
							scope : me
						}, {
							text : '门户切换',
							icon : '/hhcommon/images/extjsico/undo1_16x16.gif',
							handler : function() {
								Desktop.updateDesktop('desktop2');
							}
						}, '-', {
							text : '重新登录',
							icon : '/hhcommon/images/icons/group/group_key.png',
							handler : Desktop.onAgainLogin,
							scope : me
						}, {
							text : '身份切换',
							icon : '/hhcommon/images/icons/group/group_go.png',
							handler : Desktop.changeOrg,
							scope : me
						}, {
							text : '个人资料',
							iconCls : 'user',
							handler : Desktop.editUser,
							scope : me
						}, {
							text : '修改密码',
							icon : '/hhcommon/images/icons/building_key.png',
							handler : Desktop.changePassword,
							scope : me
						}, {
							text : '退出系统',
							icon : '/hhcommon/images/icons/page/delete.png',
							handler : Desktop.onLogout,
							scope : me
						}]
			}
		});

		return cfg;
	},
	getTaskbarConfig : function() {
		var ret = this.callParent();
		var me = this;
		return Ext.apply(ret, {
					trayItems : [{
								xtype : 'button',
								iconCls : 'user',
								handler : Desktop.onOpenMainMessage,
								scope : me
							}, {
								xtype : 'trayclock',
								flex : 1
							}]
				});
	},
	onSettings : function() {
		ExtUtil.create('com.hh.system.desktop.Settings', {
					desktop : this.desktop
				}).show();
	}
});
